<script setup>
const props = defineProps({
  selectedNode: { type: Object, required: false }
})
</script>

<template>
  <aside class="inspector">
    <h3>属性</h3>
    <div v-if="selectedNode" class="props">
      <label class="field">
        <span>X</span>
        <input type="number" min="0" step="1" v-model.number="selectedNode.x" @change="selectedNode.x = Math.max(0, Math.round(Number(selectedNode.x) || 0))" />
      </label>
      <label class="field">
        <span>Y</span>
        <input type="number" min="0" step="1" v-model.number="selectedNode.y" @change="selectedNode.y = Math.max(0, Math.round(Number(selectedNode.y) || 0))" />
      </label>
      <template v-if="selectedNode.type === 'container'">
        <label class="field">
          <span>背景色</span>
          <input type="color" v-model="selectedNode.backgroundColor" />
        </label>
        <label class="field">
          <span>使用边框</span>
          <input type="checkbox" v-model="selectedNode.useBorder" />
        </label>
        <label class="field">
          <span>边框颜色</span>
          <input type="color" v-model="selectedNode.borderColor" />
        </label>
        <label class="field">
          <span>边框宽度</span>
          <input type="number" min="0" v-model.number="selectedNode.borderWidth" />
        </label>
        <label class="field">
          <span>圆角</span>
          <input type="number" min="0" v-model.number="selectedNode.borderRadius" />
        </label>
        <label class="field">
          <span>宽度</span>
          <input type="number" min="10" v-model.number="selectedNode.width" />
        </label>
        <label class="field">
          <span>高度</span>
          <input type="number" min="10" v-model.number="selectedNode.height" />
        </label>
      </template>
      <template v-else-if="selectedNode.type === 'text'">
        <label class="field">
          <span>文字</span>
          <input type="text" v-model="selectedNode.text" />
        </label>
        <label class="field">
          <span>颜色</span>
          <input type="color" v-model="selectedNode.color" />
        </label>
        <label class="field">
          <span>字号</span>
          <input type="number" min="8" v-model.number="selectedNode.fontSize" />
        </label>
      </template>
    </div>
    <div v-else class="empty">未选择元素</div>
  </aside>
  
</template>

<style scoped>
.inspector {
  border-left: 1px solid #e5e7eb;
  padding: 16px;
  background: #f9fafb;
  overflow: auto;
}

.props {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
}

.empty {
  color: #9ca3af;
  font-size: 14px;
}

.field {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
</style>
